#include<iostream>
#include<queue>
using namespace std;

class Solution {
public:
	int reverse(int x) {
		queue<int> t;
		int y = x;
		int m = 0;
		while (x)
		{
			t.push(x%10);
			x = x / 10;
		}
		while (t.size())
		{
			if (m > INT_MAX/10 || (m == INT_MAX/10 && t.front() > 7)) return 0;
			if (m < INT_MIN/10 || (m == INT_MIN/10 && t.front() < -8)) return 0;
			m = m * 10 + t.front();
			t.pop();
		}
		return m;
	}
};

//int main()
//{
//	Solution *s = new Solution;
//	cout << s->reverse(1534236469);
//	return 0;
//}